package com.yuanxiao.impl;

import com.yuanxiao.service.EmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.util.StringUtils;


@Service
public class EmailServiceImpl implements EmailService {

    @Autowired
    private JavaMailSenderImpl javaMailSender;

    @Override
    public Boolean sendEmail(String email, String code) {
        if (StringUtils.isEmpty(email)){
            return false;
        }
        if (StringUtils.isEmpty(code)) {
            return false;

        }
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject("注册验证码");
        simpleMailMessage.setText(code);
        simpleMailMessage.setTo(email);
        simpleMailMessage.setFrom("543859079@qq.com");
        javaMailSender.send(simpleMailMessage);
        return true;
    }
}
